// strncpy模拟实现

#include <iostream>
#include <cassert>

char* strncpy_self(char* destination, const char* source, size_t count)
{
    assert(destination && source);
    char* start = destination;
    while(count && (*destination++ = *source++))
    {
        --count;
    }
    if(count)
    {
        while(count--)
        {
            *destination++ = '\0';
        }
    }
    return start;
}

int main()
{
    char s1[] = "xxxxxxxxxxxx";
    char s2[] = "hello";
    printf("%s\n", strncpy_self(s1, s2, 3));
    // printf("%s\n", strncpy_self(s1, s2, 7));

    return 0;
}
